﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
<Serializable()> Public Class Groups
    Implements ICloneable

    ''' <summary>
    ''' 污染源数组。初始状态下有一个污染源组，并且这个污染源数组始终为选中状态。
    ''' </summary>
    ''' <remarks></remarks>
    Private m_ArrayGroup(-1) As Group
    Private m_nSeiral As Integer = 0

    

    ''' <summary>
    ''' 污染源分组数组
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArrayGroup() As Group()
        Get
            Return Me.m_ArrayGroup
        End Get
        Set(ByVal value As Group())
            Me.m_ArrayGroup = value
        End Set
    End Property
    ''' <summary>
    ''' 污染源分组中的序号
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property nSeiral() As Integer
        Get
            Return Me.m_nSeiral
        End Get
        Set(ByVal value As Integer)
            Me.m_nSeiral = value
        End Set
    End Property
    'Public Sub New()
    '    Me.m_ArrayGroup(0) = New Group
    '    Me.m_ArrayGroup(0).Name = "所有"
    '    Me.m_ArrayGroup(0).GroupID = "ALL"

    '    Me.m_ArrayGroup(0).IsTypeDay = True
    '    Me.m_ArrayGroup(0).IsTypeHours = True
    'End Sub
    Public Sub AddGroup(ByVal AllSource As Source)
        ReDim Preserve m_ArrayGroup(m_ArrayGroup.Length)
        m_ArrayGroup(m_ArrayGroup.Length - 1) = New CAermod.Group
        '初始化参数
        m_ArrayGroup(m_ArrayGroup.Length - 1).IntialSource(AllSource)
        nSeiral += 1
        m_ArrayGroup(m_ArrayGroup.Length - 1).GroupID = "Group" & nSeiral
        m_ArrayGroup(m_ArrayGroup.Length - 1).Name = "分组" & nSeiral
    End Sub

    ''' <summary>
    ''' 删除1污染物组
    ''' </summary>
    ''' <param name="index"></param>
    ''' <remarks></remarks>
    Public Sub DeleteGroup(ByVal index As Integer)
        If index >= 0 And index < Me.m_ArrayGroup.Length - 1 Then
            For i As Integer = index To Me.m_ArrayGroup.Length - 2
                Me.m_ArrayGroup(i) = Me.m_ArrayGroup(i + 1)
            Next
        End If
        ReDim Preserve Me.m_ArrayGroup(Me.m_ArrayGroup.Length - 2)

    End Sub
    ''' <summary>
    ''' 根据污染物重新设置所有分组中的污染源数据
    ''' </summary>
    ''' <param name="AllSource"></param>
    ''' <remarks></remarks>
    Public Sub ResetGroupSource(ByVal AllSource As Source)
        For i As Integer = 0 To Me.m_ArrayGroup.Length - 1
            Me.m_ArrayGroup(i).ResetSource(AllSource)
        Next
    End Sub

    ''' <summary>
    ''' 输出所有污染源数组的字符串
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function OutPutGroup(ByVal Sources As Source, ByVal name As String) As String
        Dim strG As String = ""

        'strG = strG & "SO SRCGROUP  ALL" & vbCrLf
        'Me.m_ArrayGroup(0).IsZero = False '把所有源设置为有
        For i As Integer = 0 To Me.m_ArrayGroup.Length - 1
            strG = strG & Me.m_ArrayGroup(i).OutPutGroup(Sources, name)
        Next
        Return strG
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj As New Groups
        ReDim obj.m_ArrayGroup(Me.m_ArrayGroup.Length - 1)
        For i As Integer = 0 To Me.m_ArrayGroup.Length - 1
            obj.m_ArrayGroup(i) = Me.m_ArrayGroup(i).Clone
        Next
        obj.m_nSeiral = Me.m_nSeiral
        Return obj
    End Function
End Class
